﻿
@{
    ViewData["Title"] = "我的阅卷申请";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section Head{
    <link href="~/layuiadmin/style/style.css" rel="stylesheet" />
    <style>
        .layui-form-select {
            width: 100px;
            display: inline-block;
            font-size: 12px;
        }

        .layui-anim-upbit dd {
            font-size: 12px;
        }

        .layui-btn-container {
            margin: 0 !important;
        }
    </style>
}

<div id="dMain" style="padding:10px;">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-header">我的阅卷申请</div>
            <div class="layui-card-body">
                <table class="layui-hide" id="tabData" lay-filter="demo"></table>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="MenuManager-title"></div>
    <div class="layui-btn-container">
        <div class="layui-form">
            <select name="filetype"  lay-filter="filetype" id="filetype">
                <option value="-1">全部</option>
                <option value="0">待审核</option>
                <option value="1">已通过</option>
                <option value="2">不通过</option>
                <option value="3">已过期</option>
            </select>
        </div>

        <div class="text-danger" style="font-size: 14px; position: absolute; margin-top: -30px; margin-left: 110px">
            <i class="layui-icon layui-icon-triangle-r"></i> 双击行可查看该档案的详细信息！
        </div>
    </div>

    <div class="layui-inline layui-inline-secate">
        <input class="layui-input" name="id" id="test-table-demoReload" autocomplete="off" placeholder="搜索" data-type="reload">
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="text-success" lay-event="edit">编辑</a> &nbsp;
    <a class="text-danger" lay-event="del">撤回</a>
</script>
<div type="text/html" id="layerhtml" style="display:none">
    <form class="layui-form layui-form-pane " lay-filter="FilesApplyform">
        <div class="globalform FilesApplyform">
            <div class="layui-form-item">
                <div class="layui-inline">

                    <input class="layui-input" type="hidden" name="ID" />
                    <label class="layui-form-label">档案编号</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="FID" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">申请时间</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="AddTime" id="addTime" />
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">审批时间</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="AppTime" id="appTime" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline filesapplyform-select">
                        <select name="State" lay-filter="formfiletype" id="formfiletype">
                            <option value="0">待审核</option>
                            <option value="1">已通过</option>
                            <option value="2">不通过</option>
                            <option value="3">已过期</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">审批人</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="Approver" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">审核备注</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="Remarks" />
                    </div>
                </div>
            </div>
            <div class="layui-form-item">


                <div class="layui-inline">
                    <label class="layui-form-label">申请天数</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="ADate" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">申请人</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="UserId" />
                    </div>
                </div>
            </div>

            <div class="layui-form-item">

                <label class="layui-form-label">申请理由</label>
                <div class="layui-input-block">
                    <textarea name="AReason" placeholder="请输入申请理由" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="~/layuiadmin/layui/jquery.min.js"></script>
<script>
    $(document).on("click", ".layui-table-body table.layui-table tbody tr", function () {
        /*当单击表格行时,把单选按钮设为选中状态*/
        var tableDiv;
        var index = $(this).attr('data-index');
        var tableBox = $(this).parents('.layui-table-box');
        //存在固定列
        if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length > 0) {
            tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
        } else {
            tableDiv = tableBox.find(".layui-table-body.layui-table-main");
        }
        var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.layui-table-cell div.layui-form-radio I");
        if (checkCell.length > 0) {
            checkCell.click();
        }
    });
    //对td的单击事件进行拦截停止，防止事件冒泡再次触发上述的单击事件  将此代码在页面初始化后执行一次即可以。
    $(document).on("click", "td div.layui-table-cell div.layui-form-radio", function (e) {
        e.stopPropagation();
    });
</script>
<script>
    window.onload = function () {
        var statename = $("#filetype option:selected").val() == null ? -1 : $("#filetype option:selected").val();
        layui.use(['table','jquery','form'], function () {
            var table = layui.table, $ = layui.jquery,form=layui.form;

            table.render({
                elem: '#tabData',
                url: '/FilesApply/FilesApply/getFilesApply',
                where: { state: statename },
                height: 590,
                toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
                cols:
                    [
                        [
                            { title: '#', align: 'center', type: 'radio' },
                            { field: 'fileno', title: '档案编号', sort: true, align: 'center', hide: true },
                            { field: 'dwid', title: '单位编号', sort: true, align: 'center', hide: true },
                            { field: 'userID', title: '申请人', sort: true, align: 'center', hide: true },
                            { field: 'fid', title: '档案编号', sort: true, align: 'center'},
                            { field: 'aDate', title: '申请天数', sort: true, align: 'center'},
                            { field: 'aReason', title: '申请理由', align: 'center' },
                            { field: 'addTime', title: '申请时间', sort: true },
                            { field: 'state', title: '状态', sort: true, align: "center" },
                            { field: 'approver', title: '审批人', sort: true },
                            { field: 'appTime', title: '审批时间', sort: true },
                            { field: 'remarks', title: '审批备注', align: 'center' },
                            { title: '操作', align: 'center', templet: barDemo }
                        ]
                    ],
                text: {
                    none: '没有找到匹配的记录'
                }
                , height: '480px'
                , id: 'idTest'
                , page: true
            });
            form.on('select(filetype)', function (data) {
                statename = data.value
                table.reload('idTest', {
                    where: {
                        state: statename
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
                $("#filetype").val(statename)
                layui.form.render('select');
            })
        });
        layui.use(['table', 'form', 'jquery'], function () {
            var table = layui.table, form = layui.form, $ = layui.jquery;
            //监听工具条
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    layer.msg('ID：' + data.id + ' 的查看操作');
                } else if (obj.event === 'del') {
                    layer.confirm('确定撤回此条申请？', function (index) {
                        obj.del();
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    layer.open({
                        type: 1,
                        content: $("#layerhtml"),
                        title: '阅卷申请编辑',
                        area: ['680px', '400px'],
                        btn: ['确定', '取消'],
                        btn1: function (index, layero) {

                            var d = {}
                            var t = $('form').serializeArray();
                            $.each(t, function () {
                                d[this.name] = this.value
                            })
                            $.post("/FilesApply/FilesApply/EditFilesApply", {
                                data: d
                            }, function (data) {
                                layer.close(index);
                                if (data == 1) {
                                    layer.msg('修改成功', { icon: data });
                                }
                                table.reload('idTest', {
                                    where: {
                                        state: statename
                                    }
                                    , page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                })
                            }
                            )
                
                        }, btn2: function (index) {
                            layer.close(index);
                        }
                    })
                    
                    //给表单赋值
                    form.val("FilesApplyform", {
                        "ID": data.id,
                        "FID": data.fid,
                        "AddTime": data.addTime,
                        "ADate": data.aDate,
                        "State": data.state,
                        "Approver": data.approver,
                        "Remarks": data.remarks,
                        "UserId": data.userID,
                        "AppTime": data.appTime,
                        "AReason": data.aReason
                    })
                }
            });
        });
        //日期选择器
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            
            laydate.render({
                elem: '#appTime',
                format:'yyyyMMdd'
            });
            laydate.render({
                elem: '#addTime',
                format: 'yyyyMMdd' 
            });
        });
    }
</script>
